<?php $this->set('title', 'Show Survey Results'); ?>
<?php $this->set('external_css', array('presenter.css')); ?>

<!-- Survey Results Links -->
<b>Survey Results</b><br />
<?php echo $html->link("Individual", array('controller' => 'presenters', 'action' => 'search_audience')); ?> | 
<?php echo $html->link("Group", array('controller' => 'presenters', 'action' => 'group_results')); ?>

<?php
	echo $flashChart->begin();

	$i = 0;
	foreach($response_counts as $response_count) {
		// Sets the x-axis labels into the options A, B, C, etc.
		// $options is reset for each question to reflect the correct number of options.
		$options = array();
		for($j = 0; $j < count($response_count); $j++) {
			$options[] = chr($j+65);
		}
		
		echo('<p>'.($i+1).'. '.$questions[$i]['Question']['text']."<br />\n");
		echo('<span style="position:relative; left:30px;">');
		$j = 0;
		foreach($answers[$i] as $answer) {
			echo($options[$j].'. '.$answer['Answer']['text']."<br />\n");
			$j++;
		}
		echo('</span>');
		echo('</p>');
		
		$flashChart->setTitle('Question '.($i+1));
		$flashChart->setLegend('x', 'Option');
		$flashChart->setLegend('y', 'Number of Responses');
		
		// Find the max value of responses and the steps for the y-axis.
		$max = max($response_count) + 5;
		$step = (int)($max/20);
		
		$flashChart->axis('x', array('labels' => $options), false);
		$flashChart->axis('y',array('range' => array(0, $max , $step)));
		
		$flashChart->setData($response_count, '{n}', false, 'Question'.($i+1));
		echo $flashChart->chart('bar', array('colour' => '#0000FF'), 'Question'.($i+1), $i+1);
		echo $flashChart->render(300,300,++$i);
	}
?>
